package ee.logsimulator.data;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * @author Romet Piho
 * 
 */
public class Amount {

  private int amount;
  private int overkill;
  private int overheal;
  private int blocked;
  private int absorbed;
  private int resisted;
  private boolean crit;

  public Amount(String text) {
    if (text.startsWith("*")) {
      crit = true;
      amount = Integer.parseInt(text.replaceAll("\\*", ""));
    } else {
      amount = Integer.parseInt(text);
    }
  }

  public Amount(int amount, int overkill, int overheal, int blocked, int absorbed, int resisted, boolean crit) {
    this.amount = amount;
    this.overkill = overkill;
    this.overheal = overheal;
    this.blocked = blocked;
    this.absorbed = absorbed;
    this.resisted = resisted;
    this.crit = crit;
  }

  public int getAmount() {
    return amount - overheal - overkill;
  }

  public void setAmount(int amount) {
    this.amount = amount;
  }

  public boolean isCrit() {
    return crit;
  }

  public void setCrit(boolean crit) {
    this.crit = crit;
  }

  public int getOverkill() {
    return overkill;
  }

  public void setOverkill(int overkill) {
    this.overkill = overkill;
  }

  public int getOverheal() {
    return overheal;
  }

  public void setOverheal(int overheal) {
    this.overheal = overheal;
  }

  public int getBlocked() {
    return blocked;
  }

  public void setBlocked(int blocked) {
    this.blocked = blocked;
  }

  public int getAbsorbed() {
    return absorbed;
  }

  public void setAbsorbed(int absorbed) {
    this.absorbed = absorbed;
  }

  public int getResisted() {
    return resisted;
  }

  public void setResisted(int resisted) {
    this.resisted = resisted;
  }

  public boolean isBlock() {
    return blocked > 0;
  }

  public boolean isAbsorb() {
    return absorbed > 0;
  }

  public boolean isResist() {
    return resisted > 0;
  }

  public boolean isOverkill() {
    return overkill > 0;
  }

  public boolean isOverheal() {
    return overheal > 0;
  }

  @Override
  public boolean equals(Object obj) {
    return EqualsBuilder.reflectionEquals(this, obj);
  }

  @Override
  public int hashCode() {
    return HashCodeBuilder.reflectionHashCode(this);
  }

  @Override
  public String toString() {
    return "" + (crit ? "*" + getAmount() + "*" : getAmount());
  }
}
